package day14.com.zhiyou100;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Demo04 {
    public static void main(String[] args) {
        // 初始化两个容器 ArrayList  LinkedList
        int count = 10000000;
        List<String> list;
         list = new ArrayList<>();
        //list = new LinkedList<>();

        // 先测试ArrayList添加的效率
        long startTime1 = System.nanoTime();
        for (int i = 0; i < count; i++) {
            list.add("hello");
        }

        long endTime1 = System.nanoTime();
        System.out.println("arrayList添加数据花费的时间为：" + (endTime1-startTime1) + "纳秒");

        // 再测试linkedList添加的效率
        long startTime2 = System.nanoTime();
        for (int i = 0; i < count; i++) {
            list.add("hello");
        }
        long endTime2 = System.nanoTime();
        System.out.println("linkedList添加数据花费的时间为：" + (endTime2-startTime2) + "纳秒");

    }
}